//
//  MeUserTopView.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/7.
//

import UIKit

class MeUserTopView: UIView {
    
    lazy var topImage: UIImageView = {
        return UIImageView()
    }()

    lazy var topLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 14)
        label.textColor = .black
        label.textAlignment = .center
        return label
    }()
    
    var topType = 0
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .white
        addSubview(topImage)
        addSubview(topLabel)
        topImage.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(15)
            make.width.height.equalTo(32)
        }
        topLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(topImage.snp.bottom).offset(4)
        }
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapType))
        self.addGestureRecognizer(tap)
    }
    
    func setTopType(_ type: Int, _ count: Int = 0) {
        topType = type
        if type == 0 {
            topImage.image = UIImage(named: "me_topup")
            topLabel.text = "儲值"
        }else {
            topImage.image = UIImage(named: "me_wallect")
            topLabel.text = "\(count) 金幣"
        }
    }
    
    @objc func tapType() {
        if topType == 0 {
            viewContainingController?.wn_pushStoreVC()
        }else {
            let vc = WNWalletVC()
            vc.hidesBottomBarWhenPushed = true
            viewContainingController?.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
